<template>
  <div slot="header">
    <Form ref="selectObj" :model="selectObj" :rules="ruleValidate" inline :label-width="80" class="form-header">
      <FormItem label="姓名" prop="name">
        <Input v-model="selectObj.name" class="div-search" placeholder="请输入姓名"></Input>
      </FormItem>
      <FormItem label="身份证号" prop="IDcard">
        <Input v-model="selectObj.IDcard" class="div-search" placeholder="请输入身份证号"></Input>
      </FormItem>
      <FormItem>
        <Button type="primary" @click="show()" class="search-btn"><Icon type="ios-search" />搜索</Button>
      </FormItem>
    </Form>
    <div class="div-msg" ><strong>接口返回状态：</strong></div>
    <Form ref="paramData2" :model="paramData2" :label-width="80">
      <Row class="item2">
        <Col span="4" class="item-col">用户户籍状况信息：</Col>
        <Col span="6" offset="1" v-if="registerFlag === '0'" >{{paramData2.register}}</Col>
        <Col span="6" offset="1" v-if="registerFlag !== '0'" style="color: red">{{paramData2.register}}</Col>
      </Row>
      <Row class="item2">
        <Col span="4" class="item-col">用户低保状况信息：</Col>
        <Col span="12" offset="1"  v-if="lowInsuredFlag === '9999'" style="color: red">{{paramData2.allowances}}</Col>
        <Col span="12" offset="1"  v-if="lowInsuredFlag !== '9999'" >{{paramData2.allowances}}</Col>
      </Row>
      <Row class="item2">
        <Col span="4" class="item-col">用户残疾情况信息：</Col>
        <Col span="12" offset="1" v-if="disabledPersonFlag === 0" style="color: red">{{paramData2.disabledLevel}}{{paramData2.disabled}}</Col>
        <Col span="12" offset="1" v-if="disabledPersonFlag !== 0">{{paramData2.disabledLevel}}{{paramData2.disabled}}</Col>
      </Row>
      <Row class="item2">
        <Col span="4" class="item-col">用户殡葬情况信息：</Col>
        <Col span="12" offset="1" v-if="funeralPersonnelFlag === 'true'" style="color: red">{{paramData2.interment}}</Col>
        <Col span="12" offset="1" v-if="funeralPersonnelFlag === 'false'">{{paramData2.interment}}</Col>
      </Row>
    </Form>
    <div class="div-msg"><strong>接口返回信息：</strong></div>
    <Form ref="paramData2" :model="Interface" :label-width="80">
      <Row class="item1">
        <Col span="4" class="item-col">户籍信息接口地址：</Col>
        <Col span="7" ><Input readonly v-model="Interface.registerUrl" /></Col>
        <Col span="4" class="item-col">户籍信息接口返回值：</Col>
        <Col span="7"><Input readonly v-model="Interface.registerData" type="textarea" :autosize="{maxRows: 7,minRows: 1}" /></Col>
      </Row>
      <Row class="item1">
        <Col span="4" class="item-col">低保状况接口地址：</Col>
        <Col span="7" ><Input readonly v-model="Interface.allowancesUrl" /></Col>
        <Col span="4" class="item-col">低保状况接口返回值：</Col>
        <Col span="7"><Input  v-model="Interface.allowancesData" readonly type="textarea" :autosize="{maxRows: 7,minRows: 1}"/></Col>
      </Row>
      <Row class="item1">
        <Col span="4" class="item-col">残疾情况接口地址：</Col>
        <Col span="7" ><Input readonly v-model="Interface.disabledUrl" /></Col>
        <Col span="4" class="item-col">残疾情况接口返回值：</Col>
        <Col span="7"><Input  v-model="Interface.disabledData" readonly type="textarea" :autosize="{maxRows: 7,minRows: 1}"/></Col>
      </Row>
      <Row class="item1">
        <Col span="4" class="item-col">殡葬情况接口地址：</Col>
        <Col span="7" ><Input readonly v-model="Interface.intermentUrl" /></Col>
        <Col span="4" class="item-col">殡葬情况接口返回值：</Col>
        <Col span="7"><Input  v-model="Interface.intermentData" readonly type="textarea" :autosize="{maxRows: 7,minRows: 1}"/></Col>
      </Row>
    </Form>
    <div class="div_bot"></div>
  </div>
</template>

<script>
import {
  getRegisterInfo, findCanlian, getAssistanceInfo, getFuneralInfo
} from '@/api/eventlist'
export default {
  name: 'index.vue',
  data () {
    return {
      ruleValidate: {
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        IDcard: [
          { required: true, message: '身份证号不能为空', trigger: 'blur' }
        ]
      },
      registerFlag: '', // 户籍
      funeralPersonnelFlag: '', // 殡葬
      disabledPersonFlag: '', // 残疾人
      lowInsuredFlag: '', // 低保
      selectObj: {
        name: '',
        IDcard: ''
      },
      paramData2: {
        register: '', // 户籍状况
        allowances: '', // 低保状况
        disabled: '', // 残疾状况
        interment: '', // 殡葬状况
        disabledLevel: '' // 残疾等级
      },
      Interface: {
        registerUrl: '/api/uc/csc/auditRegisterService/getRegisterInfo', // 户籍接口地址
        registerData: '', // 户籍接口返回值
        allowancesUrl: '/api/ac/csc/createPostService/getAssistanceInfo', // 低保接口地址
        allowancesData: '', // 低保接口返回值
        disabledUrl: '/api/ac/dyc/streeAllServiceImpl/findCanlian', // 残联接口地址
        disabledData: '', // 残联接口返回值
        intermentUrl: '/api/ac/dyc/abutmentService/getFuneralInfo', // 殡葬接口地址
        intermentData: '' // 殡葬接口返回值
      }
    }
  },
  methods: {
    // 低保对象过滤
    formatLowPerson (val) {
      return val === '1010' ? '城市低保对象' : val === '1020' ? '城市边缘户对象' : val === '1030' ? '农村低保对象' : val === '1040' ? '农村边缘户对象' : val === '9999' ? '非保障对象' : ''
    },
    show () {
      if (this.selectObj.name === '' || this.selectObj.name === undefined) {
        this.$Modal.error({
          title: '错误',
          content: '请输入姓名'
        })
      } else if (this.selectObj.IDcard === '' || this.selectObj.IDcard === undefined) {
        this.$Modal.error({
          title: '错误',
          content: '请输入身份证号'
        })
      } else {
        this.getHouseholdRegister()
        this.getDisablePerson()
        this.getLowPerson()
        this.getFuneral()
      }
    },
    // 查询户籍状况
    getHouseholdRegister () {
      var param = { 'IDcard': this.selectObj.IDcard, 'Name': this.selectObj.name }
      getRegisterInfo(param).then(ret => {
        this.Interface.registerData = JSON.stringify(ret.data)
        if (ret.data.errcode === 0) {
          this.registerFlag = ret.data.data.result
          if (ret.data.data.result === '-1') {
            this.paramData2.register = '非沈阳户籍地'
          }
          if (ret.data.data.result === '0') {
            this.paramData2.register = '沈阳有效户籍'
          }
          if (ret.data.data.result === '1') {
            this.paramData2.register = '户籍已删除'
          }
          if (ret.data.data.result === '2') {
            this.paramData2.register = '户籍被加锁'
          }
          if (ret.data.data.result === '3') {
            this.paramData2.register = '重错号'
          }
          if (ret.data.data.result === '4') {
            this.paramData2.register = '跨市重错号'
          }
          if (ret.data.data.result === '6') {
            this.paramData2.register = '持证'
          }
          if (ret.data.data.result === '7') {
            this.paramData2.register = '在逃犯'
          }
          if (ret.data.data.result === '8') {
            this.paramData2.register = '户籍已迁出沈阳'
          }
          if (ret.data.data.result === '9') {
            this.paramData2.register = '死亡'
          }
          return
        }
        this.$Modal.error({
          title: '错误',
          content: ret.data.errmsg
        })
      })
    },
    // 查询残疾状况
    getDisablePerson () {
      let param2 = {
        cardno: this.paramData2.IDcard
      }
      findCanlian(param2).then(ret => {
        this.Interface.disabledData = JSON.stringify(ret.data)
        if (ret.data.errcode === 0) {
          this.disabledPersonFlag = ret.data.data.length
          if (ret.data.data.length === 0) {
            this.paramData2.disabled = '非残疾人'
            this.paramData2.disabledLevel = ''
          } else if (itemId === '11210101000000MZJD5212000216000') {
            this.paramData2.disabled = ret.data.data[0].DISABLED_TYPE_NAME
            if (ret.data.data[0].DISABLED_LEVEL !== '一级' && ret.data.data[0].DISABLED_LEVEL !== '二级') {
              this.paramData2.disabledLevel = '非一，二级'
            } else {
              this.paramData2.disabledLevel = ret.data.data[0].DISABLED_LEVEL
            }
          } else {
            this.paramData2.disabled = ret.data.data[0].DISABLED_TYPE_NAME
            this.paramData2.disabledLevel = ret.data.data[0].DISABLED_LEVEL
          }
          return
        }
        this.$Modal.error({
          title: '错误',
          content: ret.data.errmsg,
          onOk: () => {
          }
        })
      })
    },
    // 查询低保情况
    getLowPerson () {
      let param1 = {
        'azcp0001': this.selectObj.IDcard,
        'idcardNumber': this.selectObj.IDcard,
        'serialNumber': '123456'
      }
      getAssistanceInfo(param1).then(ret => {
        this.Interface.allowancesData = JSON.stringify(ret.data)
        if (ret.data.errcode === 0) {
          if (ret.data.data.rescode === '0000') {
            this.lowInsuredFlag = ret.data.data.data.type
            this.paramData2.allowances = this.formatLowPerson(ret.data.data.data.type)
            return
          }
          this.$Modal.error({
            title: '错误',
            content: ret.data.data.memo
            /* onOk: () => {
             this.modal1 = false
             } */
          })
          return
        }
        this.$Modal.error({
          title: '错误',
          content: ret.data.errmsg,
          onOk: () => {
            this.modal1 = false
          }
        })
      })
    },
    // 查询殡葬
    getFuneral () {
      let param1 = {
        'idCode': this.selectObj.IDcard
      }
      getFuneralInfo(param1).then(ret => {
        this.Interface.intermentData = JSON.stringify(ret.data)
        if (ret.data.errcode === 0) {
          this.funeralPersonnelFlag = ret.data.data.flag
          if (ret.data.data.flag === 'false') {
            this.paramData2.interment = '未查询到该人员殡葬信息'
            return
          }
          if (ret.data.data.flag === 'true') {
            this.paramData2.interment = '登记死亡人员,请精神操作'
            return
          }
          this.$Modal.error({
            title: '错误',
            content: ret.data.data.memo
            /* onOk: () => {
              this.modal1 = false
              } */
          })
          return
        }
        this.$Modal.error({
          title: '错误',
          content: ret.data.errmsg,
          onOk: () => {
            this.modal1 = false
          }
        })
      })
    }
  }
}
</script>

<style scoped>
  .item1{
    line-height: 40px;
    margin-top: 10px;
  }
  .item2{
    height: 42px;
    line-height: 40px;
  }
  .div_bot{
    margin-top: 50px;
  }
  .item-col{
    text-align: right;
  }
  .div-msg{
    margin: 10px 0;
    font-size: 15px;
  }
  .div-search{
    width: 200px;
  }
  .form-header{
    height: 40px;
  }
  .search-btn{
    margin-left: -55px;
  }
</style>
